package com.xcity.game.combat.skill.impl;

import java.util.List;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.CombatUtils;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 遍地开花<br/>
 * 撤资只是为了更好的投资，随机挑选{0=3#0}个目标造成{1=40#0}%技能伤害，并对最后一个目标额外造成一次{2=50#0}%的技能伤害
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90112 extends CombatSkill {

	public COMBAT_SKILL_90112(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		int n = (int) skill.getParameter(0);
		float rate = skill.getParameter(1) / GameStaticConfig.percentBase;
		float lastRate = skill.getParameter(2) / GameStaticConfig.percentBase;
		List<CombatUnit> targets = action.target.getUnitsRandomly(n);
		CombatUnit lastTarget = null;
		for (int i = 0, size = targets != null ? targets.size() : 0; i < size; i++) {
			CombatUnit u = targets.get(i);
			if (!u.isDied()) {
				ActionEffect effect = action.addTarget(u);
				u = effect.getUnit(); // 修正目标
				CombatUtils.calcMagicAttack(effect, rate);
				lastTarget = u;
			}
		}
		if (lastTarget != null && !lastTarget.isDied()) {
			Action newAct = new Action(action.unit);
			action.ref().add(newAct);
			ActionEffect effect = newAct.addTarget(lastTarget);
			CombatUtils.calcMagicAttack(effect, lastRate);
		}
	}

}
